let log = console.log
let arr = ['首页', '搜索', '购物车', '我的']
/**
 * 描述 给li绑定点击事件，让li处于激活状态
 * @date 2020-09-24
 * @returns {any}
 */
function fn() {
    //1、找到所有的li元素
    let list = document.querySelectorAll('#app>ul>li')
    for (let i = 0, len = list.length; i < len; i++) {
        list[i].onclick = function () {
            for (let j = 0, length = list.length; j < length; j++) {
                list[j].setAttribute('class', '')
                if (i === j) {
                    list[j].setAttribute('class', 'active')
                    main.innerHTML = arr[j]
                }
            }
        }
    }
}
fn()